package com.carassistant.beta.common.dialog;


import com.carassistant.beta.R;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
/***
 * 对话框基类
 * @author james
 *
 */
public class BaseDialog  extends Dialog {
	protected Context context;
	protected LayoutInflater inflater;
	protected OnDialogClickListener mListener ;
	public boolean clickWithDismiss = true;
	protected TextView titleView  ;
	/**
	 * 构造方法
	 * @param context
	 */
	public BaseDialog(Context context) {
		super(context, R.style.MyDialog);
		this.setCanceledOnTouchOutside(false);

		this.context = context;
		this.inflater = LayoutInflater.from(context);
		mListener = new OnDialogClickListener(this);
	}

	private class OnDialogClickListener implements android.view.View.OnClickListener{
		private Dialog dialog;
		public OnDialogClickListener(Dialog dialog){
			this.dialog = dialog;
		}
		@Override
		public void onClick(View v) {
			if (null != v.getTag()) {
				OnDialogButtonClickListener odbcl = (OnDialogButtonClickListener)v.getTag();
				odbcl.onClick(dialog, v);
			}
			if (clickWithDismiss) {
				dialog.dismiss();
			}
		}
	}

	public interface OnDialogButtonClickListener{
		public void onClick(Dialog dialog,View v);
	}
}
